<template>
  <div class="repay-detail">
    <fieldset>
      <legend style="margin-left:-12px;" class="field-title">申请信息</legend>
      <config-form :initData="this.allFormData.bacisInfo" :span="6" :options="BACIS_FORM" />
    </fieldset>
    <fieldset>
      <legend style="margin-left:-12px;" class="field-title">客户信息</legend>
      <config-form :initData="this.allFormData.customerInfo" :span="6" :options="REPAY_FORM" />
      <config-form :initData="this.allFormData.customerInfo" :span="6" :options="CONTACT_1" />
      <config-form :initData="this.allFormData.customerInfo" :span="6" :options="CONTACT_2" />
    </fieldset>
    <fieldset>
      <legend style="margin-left:-12px;" class="field-title">逾期信息</legend>
      <config-form :initData="this.allFormData.overDetails" :span="6" :options="LOAN_FORM" />
      <el-row class="table-top">
      <el-table :data="this.allFormData.overDetails.overList" v-loading="tableLoading" tooltip-effect="light" class="tc-table" size="small">
        <template v-for="(column, index) in OVER_HEAD_LIST">
          <el-table-column :prop="column.prop" :label="column.label" :key="index" :width="column.width" :show-overflow-tooltip="true" />
        </template>
      </el-table>
      <!-- <el-row class="pagination-top">
        <pagination :pageNum.sync="dataForm.pageNum" :curSizes.sync="dataForm.pageSize" :total="total" @getList="getList" />
      </el-row> -->
    </el-row>
    </fieldset>
    <fieldset>
      <legend style="margin-left:-12px;" class="field-title">跟进情况</legend>
      <config-form :initData="this.allFormData.fllowHistoryInfo" :span="6" :options="FOLLOW_FORM_INFO" />
      <el-row class="table-top">
        <el-table :data="this.allFormData.fllowHistoryInfo.followList" v-loading="tableLoading1" tooltip-effect="light" class="tc-table" size="small">
          <template v-for="(column, index) in FOLLOW_HEAD_LIST">
            <el-table-column :prop="column.prop" :label="column.label" :key="index" :width="column.width" :show-overflow-tooltip="true" />
          </template>
        </el-table>
        <!-- <el-row class="pagination-top">
          <pagination :pageNum.sync="dataForm.pageNum" :curSizes.sync="dataForm.pageSize" :total="total" @getList="getList" />
        </el-row> -->
    </el-row>
    </fieldset>
    <el-row>
      <el-col :span="24" :offset="20">
        <el-button type="" @click="close">关闭</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import api from '../api'
import { CONSTANT_OBJ } from '@/utils/constant'
import {
  disposePhone,
  encryptIdNo,
  encryptName,
  disposeAddress,
  disposeComName
} from '@/utils/util'
import { BACIS_FORM, REPAY_FORM, LOAN_FORM, OVER_HEAD_LIST, FOLLOW_FORM_INFO, FOLLOW_HEAD_LIST, CONTACT_1, CONTACT_2 } from '../js/contant.js'
export default {
  props: { overdata: Object },
  data () {
    return {
      BACIS_FORM,
      REPAY_FORM,
      LOAN_FORM,
      OVER_HEAD_LIST,
      FOLLOW_FORM_INFO,
      FOLLOW_HEAD_LIST,
      CONTACT_1,
      CONTACT_2,
      repayForm: {},
      repayOverdueCustomerInfo: {},
      tableLoading: false,
      tableLoading1: false,
      allFormData: {
        bacisInfo: {}, // 基本信息
        customerInfo: {}, // 客户信息
        fllowHistoryInfo: {}, // 跟进记录
        overDetails: {} // 逾期详情
      },
      dataForm: {
        pageNum: 0,
        pageSize: 10
      }
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    init () {
      this.getOverData()
      this.getBasicInfo()
      this.getCustomerInfomation()
      this.getOverFllow()
    },
    // 获取逾期详情数据
    getOverData () {
      api.getQueryByIdRepayData(this.overdata.overdueId).then(res => {
        const { responseCode, data } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          data.forEach(el => {
            el.newPayType = this.dicts['fee_pay_type'].childMap[el.feePayType]
            el.newStatus = this.dicts['repay_current_status'].childMap[el.currentStatus]
            el.newPeriods = this.dicts['loan_periods'].childMap[el.loanPeriods]
          })
          this.allFormData.overDetails = {
            ...this.overdata,
            overList: [...data]
          }
          console.log(this.allFormData.overDetails, '逾期数据')
        }
      })
    },
    // 获取基本信息
    getBasicInfo () {
      api.getBasicInfoData(this.overdata.caseId).then(res => {
        const { responseCode, data } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          data.newProductType = this.dicts['product_type'].childMap[data.productType]
          this.queryScheduleFllowEvent(data)
        }
      })
    },
    // 获取最新进度结果
    queryScheduleFllowEvent (bData) {
      api.queryScheduleFllow({caseId: this.overdata.caseId}).then(res => {
        const { responseCode, data } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          data.data.newFee = data.data.rateList.map(ele => this.dicts['fee_pay_type'].childMap[ele.feePayType]).join(',')
          data.data.newMaxPeriods = data.data.rateList.map(ele => `${this.dicts['fee_pay_type'].childMap[ele.feePayType]}:${this.dicts['loan_periods'].childMap[ele.maxPeriods]}`).join(',')
          data.data.newIrrRate = data.data.rateList.map(ele => `${this.dicts['fee_pay_type'].childMap[ele.feePayType]}:${ele.irrRate}%`).join(',')
          let cData = Object.assign(data.data, bData)
          this.allFormData.bacisInfo = {...cData}
        }
      })
    },
    // 获取申请客户信息
    getCustomerInfomation () {
      api.getCustomerInfo(this.overdata.caseId).then(res => {
        const { responseCode, data } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          data.idDate = `${data.idBeginDate}-${data.idEndDate}`
          data.newEducation = this.dicts['education'].childMap[data.education]
          data.newHouseStatus = this.dicts['house_status'].childMap[data.houseStatus]
          data.newMaritalStatus = this.dicts['marital_status'].childMap[data.maritalStatus]
          data.newCustName = encryptName(data.customerName)
          data.newIdNbr = encryptIdNo(data.idNbr)
          data.newCusPhone = disposePhone(data.customerPhone)
          data.newIdAddress = disposeAddress('idcard', data.idAddress)
          data.nowAddr = `${data.homeAddress.province}-${data.homeAddress.city}-${data.homeAddress.town}-*******`
          data.nowAddress = `${data.homeAddress.province}-${data.homeAddress.city}-${data.homeAddress.town}-*******`
          this.getCustomerCareer(data)
        }
      })
    },
    // 获取客户职业信息
    getCustomerCareer (bData) {
      api.getCareerInfo(this.overdata.caseId).then(res => {
        const { responseCode, data } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          data.newWorkTime = this.dicts['work_time'].childMap[data.workTime]
          data.newOrganPhone = disposePhone(data.organPhone)
          data.organAddr = `${data.organAddress.province}-${data.organAddress.city}-${data.organAddress.town}-${data.organAddress.street}`
          data.newOrganAddr = `${data.organAddress.province}-${data.organAddress.city}-${data.organAddress.town}-*******`
          data.newOrganName = disposeComName(data.organName)
          let cData = Object.assign(data, bData)
          this.getCustomerContact(cData)
        }
      })
    },
    // 获取客户联系人信息
    getCustomerContact (bData) {
      api.getContactInfo(this.overdata.caseId).then(res => {
        const { responseCode, data } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          data.contactName_1 = encryptName(data[0].contactName)
          data.contactPhone_1 = disposePhone(data[0].contactPhone)
          data.newContactName_1 = data[0].contactName
          data.newContactPhone_1 = data[0].contactPhone
          data.contactRelation_1 = this.dicts['contact_relation_1'].childMap[data[0].contactRelation]
          data.isKnow_1 = data[0].isKnow === 'Y' ? '是' : '否'
          data.contactName_2 = encryptName(data[1].contactName)
          data.contactPhone_2 = disposePhone(data[1].contactPhone)
          data.newContactName_2 = data[1].contactName
          data.newContactPhone_2 = data[1].contactPhone
          data.contactRelation_2 = this.dicts['contact_relation_2'].childMap[data[1].contactRelation]
          data.isKnow_2 = data[1].isKnow === 'Y' ? '是' : '否'
          let cData = Object.assign(data, bData)
          this.allFormData.customerInfo = {...cData}
        }
      })
    },
    // 获取逾期跟进记录
    getOverFllow () {
      api.getOverFllowHistory({overdueId: this.overdata.overdueId}).then(res => {
        const { responseCode, data } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          let result = {...this.overdata}
          console.log(data, '跟进记录')
          result.newStatus = this.dicts['repay_follow_status'].childMap[result.currentStatus]
          if (data.length > 0) {
            data.forEach(v => {
              v.newRes = this.dicts['overdue_follow_result'].childMap[v.followResult] || ''
              v.newName = encryptName(v.customerName)
              v.newAddr = v.organCity ? `${v.organCity}-${v.organTown}` : ''
              v.newProduct = this.dicts['product_type'].childMap[v.productType]
              v.newPhone = disposePhone(v.callPhone)
            })
          }
          this.allFormData.fllowHistoryInfo = {
            ...result,
            followList: [...data]
          }
          console.log(this.allFormData.fllowHistoryInfo, '根据情况')
        }
      })
    },
    close () {
      this.$emit('close', false)
    }
  },
  computed: {
    ...mapState({
      dicts: state => state.common.dicts
    })
  }
}
</script>
<style lang="less" scoped>
@import "../../../assets/css/global.less";
.repay-detail {
  fieldset {
    padding: 0 10px;
    margin-bottom: 10px;
    border-color: @theme-color;
  }
  .field-title {
    color: @theme-color;
  }
  .el-form-item--mini.el-form-item.isEdit {
    margin-bottom: 5px;
  }
}
</style>
